API Documentation
Public Member Functions | List of all members
nkMemory::FreeListPager< T, U > Class Template Referencefinal

A pager implementing the free list pattern. More...

Public Member Functions

 FreeListPager (size_t pageSize)
 
 ~FreeListPager ()=default
 
size_t getPageSize () const
 
size_t getAllocatedPageCount () const
 
const FreeListMemorySpaceWrapper< T, U > & getPage (size_t index)
 
FreeListAllocation< T > allocate (size_t size, size_t alignment=1)
 
void free (size_t allocationIndex)
 

Detailed Description

template<typename T = char*, typename U = DefaultMemorySpace>
class nkMemory::FreeListPager< T, U >

A pager implementing the free list pattern.

This pattern keeps track of allocations within the pages, and returns allocations fitting the requirements within the memory space allocated. Allocations can be freed individually. This pager can be used when data will be kept around, with no knowledge about the lifetime of it.
For instance, in a 3d renderer, gpu resources can be placed within a memory space as they come and go, reducing the need for memory allocations.

Constructor & Destructor Documentation

◆ FreeListPager()

template<typename T = char*, typename U = DefaultMemorySpace>
nkMemory::FreeListPager< T, U >::FreeListPager ( size_t  pageSize)

Constructor.

Parameters
pageSizeThe size to use for pages.

◆ ~FreeListPager()

template<typename T = char*, typename U = DefaultMemorySpace>
nkMemory::FreeListPager< T, U >::~FreeListPager ( )
default

Destructor.

Member Function Documentation

◆ getPageSize()

template<typename T = char*, typename U = DefaultMemorySpace>
size_t nkMemory::FreeListPager< T, U >::getPageSize ( ) const
Returns
The page size used by the pager.

◆ getAllocatedPageCount()

template<typename T = char*, typename U = DefaultMemorySpace>
size_t nkMemory::FreeListPager< T, U >::getAllocatedPageCount ( ) const
Returns
The number of pages currently allocated.

◆ getPage()

template<typename T = char*, typename U = DefaultMemorySpace>
const FreeListMemorySpaceWrapper<T, U>& nkMemory::FreeListPager< T, U >::getPage ( size_t  index)
Returns
Returns a page kept internally. Should not be called by external code.

◆ allocate()

template<typename T = char*, typename U = DefaultMemorySpace>
FreeListAllocation<T> nkMemory::FreeListPager< T, U >::allocate ( size_t  size,
size_t  alignment = 1 
)

Requests an allocation.

Parameters
sizeThe size of the allocation needed.
alignmentThe needed alignment in the memory space.
Returns
An allocation fitting requested conditions, if possible.
Remarks
Typically, a failure in allocating is caused by the page size being too small.

◆ free()

template<typename T = char*, typename U = DefaultMemorySpace>
void nkMemory::FreeListPager< T, U >::free ( size_t  allocationIndex)

Releases an allocation so that it returns within the pager.

Parameters
allocationIndexThe index for the allocation to free. Provided by allocate().

The documentation for this class was generated from the following file: